package com.hockeo.server.rpc.command;

import com.hockeo.shared.rpc.command.ICommand;
import com.hockeo.shared.rpc.command.IResponse;
import com.hockeo.shared.rpc.command.error.CommandException;
import com.hockeo.shared.rpc.command.error.ExecutionFailedException;

/**
 * Base interface to be implemented by all command handlers.
 *
 * @param <S> the type of the command to handle
 * @param <R> the type of the response of the handled command
 * @version $Id$
 * @author jjanke
 */
public interface ICommandExecutor<S extends ICommand<R>, R extends IResponse>
{
  /**
   * Returns the type of the handled command.
   */
  public Class<S> getCommandType();

  /**
   * Executes the given command.
   *
   * @param ctx the current command execution context
   * @param command the command to be executed
   * @return the command processing result
   * @throws CommandException if the command execution fails
   */
  public R execute( CommandExecutionContext ctx, S command ) throws ExecutionFailedException;
}
